package com.ra.controller;


import com.ra.pojo.RespBean;
import com.ra.pojo.RespPageBean;
import com.ra.pojo.dto.ConditionDTO;
import com.ra.pojo.dto.RoleDTO;
import com.ra.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 今晚几点睡_Ada
 * @since 2023-03-09
 */
@RestController
@Api(tags = "角色模块")
public class RoleController {
    @Autowired
    private IRoleService roleService;

    @ApiOperation(value = "保存或更新角色")
    @PostMapping("/admin/role")
    public RespBean<?> saveOrUpdateRole(@RequestBody @Valid RoleDTO roleDTO) {
        roleService.saveOrUpdateRole(roleDTO);
        return RespBean.success();
    }

    @ApiOperation(value = "删除角色")
    @DeleteMapping("/admin/roles")
    public RespBean<?> deleteRoles(@RequestBody List<Integer> roleId) {
        roleService.deleteRoles(roleId);
        return RespBean.success();
    }
    @ApiOperation(value = "查询角色列表")
    @GetMapping("/admin/roles")
    public RespBean<RespPageBean<RoleDTO>> listRoles(ConditionDTO conditionDTO) {
        return RespBean.success(roleService.listRoles(conditionDTO));
    }

}

